﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _3._1
{
    class Rectangle:shape
    {
        
        private double width { get; set; }
        private double height;

        public Rectangle(double width, double height)
        {
            this.width = width;
            this.height = height;
            if (!this.check())
            {
                Console.WriteLine("长方形不合法,取默认，width为3，height为2");
                this.width = 3;
                this.height = 2;
            }
        }

        public override string ToString()
        {
            double s = this.area();
            return "这是一个长方形,高：" + height.ToString("f3") + ",宽：" + width.ToString("f3") + ",面积："+s.ToString("f3") + "\n";
        }

        public override  double area()
        {
            return this.width * this.height;
        }

        public override bool check()
        {
            if (width > 0 && height > 0)
            {
                return true;
            }
            return false;
        }
    }
}
